package com.yuanss.smartdemo.service;



import com.yuanss.smartdemo.helper.DatabaseHelper;
import com.yuanss.smartdemo.model.Customer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description 提供客户端数据服务
 * @Date 2024/11/15 上午11:04
 * @Created by 菜到不敢run
 */
public class CustomerService {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomerService.class);

    // 获取客户列表
    public List<Customer> getCustomerList(String keyword){
        String sql = "select * from Customer";
        return DatabaseHelper.queryEntityList(Customer.class,sql);
    }

    public Customer getCustomerById(long id){
        String sql = "select * from Customer where id = ?";
        return DatabaseHelper.queryEntity(Customer.class,sql, id);
    }

    public boolean createCustomer(Map<String,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    public boolean updateCustomer(Map<String,Object> fieldMap, long id){
        return DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    public boolean deleteCustomer(long id){
        return DatabaseHelper.deleteEntity(Customer.class,id);
    }
}
